package com.team.arms.political.controller;


import com.team.arms.common.ry.core.domain.AjaxResult;
import com.team.arms.political.domain.ZPoliRecord;
import com.team.arms.political.mapper.ZPoliRecordMapper;
import com.team.arms.political.service.IZPoliRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * mapperController
 * 
 * @author ruoyi
 * @date 2022-05-16
 */
@RestController
@RequestMapping("/Record")
@Api(tags = "政治考核-政审详细")
public class ZPoliRecordController
{
    @Autowired
    private IZPoliRecordService zPoliRecordService;
    @Autowired
    private ZPoliRecordMapper zPoliRecordMapper;
    /**
     * 查询mapper列表
     */
/*    @ApiOperation("条件查询所有信息")
    @GetMapping("/list")
    public AjaxResult list(@RequestBody ZPoliRecord zPoliRecord)
    {

        List<ZPoliRecord> list = zPoliRecordService.selectZPoliRecordList(zPoliRecord);
        return AjaxResult.success("查找成功",list);

    }*/

//    /**
//     * 导出mapper列表
//     */
//    @Log(title = "mapper", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ZPoliRecord zPoliRecord)
//    {
//        List<ZPoliRecord> list = zPoliRecordService.selectZPoliRecordList(zPoliRecord);
//        ExcelUtil<ZPoliRecord> util = new ExcelUtil<ZPoliRecord>(ZPoliRecord.class);
//        util.exportExcel(response, list, "mapper数据");
//    }

    @GetMapping(value = "/{poliInfoId}")
    @ApiOperation("根据政审id查询政审记录")
    public AjaxResult getInfo(@PathVariable("poliInfoId") String poliInfoId)
    {
        ZPoliRecord zPoliRecord = zPoliRecordService.selectZPoliRecordByPoliRecordId(poliInfoId);
        return AjaxResult.success("操作成功",zPoliRecord);
    }


    @PostMapping
    @ApiOperation("添加政审记录")
    public AjaxResult add(@RequestBody ZPoliRecord zPoliRecord)
    {
        ZPoliRecord zPoliRecordold = zPoliRecordService.selectZPoliRecordByPoliRecordId(zPoliRecord.getPoliInfoId());

//        List<ZPoliRecord> zPoliRecords = zPoliRecordMapper.selectZPoliRecordByPoliinfoid(zPoliRecord.getPoliInfoId());
        if  (zPoliRecordold != null){
            return AjaxResult.error("已有政审详细数据,新增失败");
        }
        int i =zPoliRecordService.insertZPoliRecord(zPoliRecord);
        if(i>0){
            return AjaxResult.success("新增成功",zPoliRecord);

        }
        return AjaxResult.error("新增失败");


    }


/*    @PutMapping
    public AjaxResult edit(@RequestBody ZPoliRecord zPoliRecord)
    {
        int i =zPoliRecordService.updateZPoliRecord(zPoliRecord);
        if(i>0){
            return AjaxResult.success("修改成功",zPoliRecord);

        }
        return AjaxResult.error("修改失败");
    }*/


	@DeleteMapping("/{poliInfoIds}")
    @ApiOperation("根据政审id删除政审信息")
    public AjaxResult remove(@PathVariable Long[] poliInfoIds)
    {
        int i =   zPoliRecordService.deleteZPoliRecordByPoliRecordIds(poliInfoIds);
        if(i>0){
            return AjaxResult.success("删除成功");

        }
        return AjaxResult.error("删除失败");

    }
}
